package com.aijk.web.admin.controller.openapi;


import com.aijk.ehm.captcha.api.CaptchaApi;
import com.aijk.ehm.captcha.entity.CaptchaType;
import com.aijk.ehm.captcha.entity.SmsCaptchaCreateReq;
import com.aijk.web.admin.controller.openapi.entity.ApiEntity;
import com.aijk.web.admin.controller.openapi.entity.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * 用户类API接口
 */
@Component
@Controller
public class DemoController extends ApiBaseController {

    private static final Logger logger = LoggerFactory.getLogger(DemoController.class);

    @Autowired
    private CaptchaApi captchaApi;


    @RequestMapping(path = "app/demo", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object demo(@Valid ApiEntity entity) {
        logger.info("request={}", entity);
        ApiResponse response = new ApiResponse();
        response.setData(entity);
        return response;
    }

    @RequestMapping(path = "app/send", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object send(@Valid ApiEntity entity) {
        logger.info("request={}", entity);
        SmsCaptchaCreateReq req = new SmsCaptchaCreateReq();
        req.setType(CaptchaType.SMS);
        req.setMobile("18158133355");
        req.setKey("ehm");
        req.setLen(4);
        captchaApi.create(req);
       return new ApiResponse();
    }


}
